package com.xlhj.boot.util;

import com.aliyun.odps.Odps;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author: caijliu
 * @description: MaxCompute工具类
 * @data: 23/06/2021 9:48
 */
@Component
public class MaxComputeUtils {

    private static String accessIds;
    private static String accessKeys;
    private static String endPoints;
    private static String projects;

    @Value("${aliyun.config.accessId}")
    private String accessId;
    @Value("${aliyun.config.accessKey}")
    private String accessKey;
    @Value("${aliyun.config.endPoint}")
    private String endPoint;
    @Value("${aliyun.config.project}")
    private String project;

    @PostConstruct
    public void getAccessId() {
        accessIds = accessId;
    }
    @PostConstruct
    public void getAccessKey() {
        accessKeys = accessKey;
    }
    @PostConstruct
    public void getEndPoint() {
        endPoints = endPoint;
    }
    @PostConstruct
    public void getProject() {
        projects = project;
    }

    /**
     * 获取Odps实例
     * @return
     */
    public static Odps getOdps() {
        Account account = new AliyunAccount(accessIds, accessKeys);
        Odps odps = new Odps(account);
        odps.setEndpoint(endPoints);
        odps.setDefaultProject(projects);
        return odps;
    }
}
